<?php

namespace app\index\controller;

use think\Controller;
use think\Db;

class Follow extends Controller
{
	public function get_follower($user_id = 39)
	{
		$ids = Db::query("select follow_id from ym_user_follow where user_id = '$user_id'");
		if (!empty($ids)) {
			$str='';
			$length = count($ids);
            for ($i=0; $i < $length; $i++) {
                $follow_id = $ids[$i]['follow_id'];
                if($i == 0){
                	$str.=$follow_id;
                }
                else{
                	$str.=','.$follow_id;
            	}
            }
            $follow_ids = $str;
            $dynamic = Db::query("select b.user_id,b.user_name,b.user_icon,a.dynamic_id,a.content,a.latitude as post_latitude,a.longitude as post_longitude,a.user_address,a.send_time from ym_user_dynamic as a left join user_info as b on a.user_id=b.user_id  where a.user_id in($follow_ids) ORDER BY a.send_time limit 0, 3");
            $length = count($dynamic);
            for ($i=0; $i < $length; $i++) {
                $dynamic_id = $dynamic[$i]['dynamic_id'];
                $img = Db::query("select img_url from ym_user_dynamic_img where dynamic_id = '$dynamic_id'");
                $dynamic[$i]['img_urls'] = $img;
                $upvoteCount = Db::query("select upvoteCount from ym_user_dynamic_upvoteCount where dynamic_id = '$dynamic_id'");
                // var_dump($upvoteCount);
                $dynamic[$i]['upvoteCount'] = $upvoteCount[0]['upvoteCount'];
                $count = Db::query("select count(*) as count from ym_user_dynamic_cmmt where dynamic_id = '$dynamic_id'");
                $dynamic[$i]['cmmt_count'] = $count[0]['count'];
                $upvote = Db::query("select upvote from ym_user_dynamic_upvote where dynamic_id = '$dynamic_id' and user_id = '$user_id'");
                if (is_null($upvote[0]['upvote'])) {
                    $dynamic[$i]['upvote'] = 0;
                }else{
                    $dynamic[$i]['upvote'] = $upvote[0]['upvote'];
                }
            }
            print_r($dynamic);
			/*foreach($ids as $id)
			{
				$follow_ids = $id[follow_id];
				$dynamic = Db::query("select b.user_id,b.user_name,b.user_icon,a.dynamic_id,a.content,a.latitude as post_latitude,a.longitude as post_longitude,a.user_address,a.send_time from ym_user_dynamic as a left join user_info as b on a.user_id=b.user_id  where a.user_id in($follow_ids) ORDER BY a.send_time");
				$length = count($dynamic[0]);
				echo $length;
				var_dump($dynamic);
				echo "<br/>";
			}*/
            //$length = count($ids);
            //for ($i=0; $i < $length; $i++) {
            //   $follow_id = $ids[$i]['follow_id'];
            //    $str=','.$follow_id;
            }
	}
	
}